package org.jeecg.modules.simulator.factory.orbit;

import lombok.Setter;
import org.jeecg.modules.simulator.factory.station.json.Stationbs;
import org.jeecg.modules.simulator.model.orbit.OrbitPoint;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @program: 轨道
 * @description:
 * @author: renzhg
 * @create: 2024-08-07 10:11
 **/
public class TracksFactory  {


    @Getter
    List<OrbitPoint> orbitPath=new ArrayList<>();



    @Setter
    List<Stationbs> stationbsList =new ArrayList<>();



    public void initReadOrbitPath( ) {

        Map<String, List<Stationbs>> groupedByCategory = stationbsList.stream()
                .collect(Collectors.groupingBy(Stationbs::getLineId));
//        groupedByCategory 循环

        for (Map.Entry<String, List<Stationbs>> entry : groupedByCategory.entrySet()) {

            for (int i = 1; i < entry.getValue().size(); i++) {
                OrbitPoint orbitPointStation = new OrbitPoint();
                Stationbs stationbsbefore = entry.getValue().get(i - 1);
                orbitPointStation.setOrbitName(stationbsbefore.getName());
                orbitPointStation.setIndex(2*i-1);
                orbitPointStation.setLineId(stationbsbefore.getLineId());
                orbitPointStation.setStartOffsetDistance(stationbsbefore.getStartOffset());
                orbitPointStation.setEndOffsetDistance(stationbsbefore.getEndOffset());
                orbitPointStation.setBelongingType("station");
                orbitPath.add(orbitPointStation);
//            orbitPath.put(stationbsbefore.getName(),orbitPointStation);
                OrbitPoint orbitPointSect = new OrbitPoint();
                Stationbs stationbs = entry.getValue().get(i);
                orbitPointSect.setOrbitName(stationbsbefore.getName()+"-"+stationbs.getName());
                orbitPointSect.setBelongingType("section");
                orbitPointSect.setLineId(stationbsbefore.getLineId());
                orbitPointSect.setIndex(2*i);
                orbitPointSect.setStartOffsetDistance(stationbsbefore.getEndOffset());
                orbitPointSect.setEndOffsetDistance(stationbs.getStartOffset());
                orbitPath.add(orbitPointSect);
//            orbitPath.put(stationbsbefore.getName()+"-"+stationbs.getName(),orbitPointSect);

            }
            OrbitPoint orbitPointStation1 = new OrbitPoint();
            Stationbs  stationbs= entry.getValue().get(entry.getValue().size()-1);
            orbitPointStation1.setOrbitName(stationbs.getName());
            orbitPointStation1.setIndex(2*(entry.getValue().size())-1);
            orbitPointStation1.setLineId(stationbs.getLineId());
            orbitPointStation1.setStartOffsetDistance(stationbs.getStartOffset());
            orbitPointStation1.setEndOffsetDistance(stationbs.getEndOffset());
            orbitPointStation1.setBelongingType("station");
            orbitPath.add(orbitPointStation1);



        }




    }




}
